package com.enqualcomm.kids.bean;

import com.amap.api.maps.model.LatLng;
import com.enqualcomm.kids.network.socket.response.LocusResult;


import java.util.ArrayList;
import java.util.List;


/**
 * Created by yinzhiqun on 2015/12/2.
 *
 */
public class CalculateResult{
    /**
     * 进行线路规划的起点
     */
    public LocusResult.Data start;

    /**
     * 进行线路规划的终点
     */
    public LocusResult.Data end;

    /**
     * 规划的结果
     */
    public List<LatLng> calculatePoints;

    /**
     * 规划总长度
     */
    public float distance;


    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();

        if (calculatePoints!=null&&!calculatePoints.isEmpty()){
            for (int i = 0,size = calculatePoints.size(); i <size ; i++) {
                LatLng latLng = calculatePoints.get(i);
                stringBuilder.append(latLng.latitude)
                        .append(",")
                        .append(latLng.longitude)
                        .append("#");
            }
            stringBuilder.deleteCharAt(stringBuilder.length()-1);
        }

        return stringBuilder.toString();
    }

    public static CalculateResult fromString(String str){
        CalculateResult calculateResult = new CalculateResult();
        calculateResult.calculatePoints = new ArrayList<>();
        String[] split = str.split("#");

        for (int i = 0,size = split.length; i < size; i++) {
            String[] latlng = split[i].split(",");
            calculateResult.calculatePoints.add(new LatLng(Double.parseDouble(latlng[0]),Double.parseDouble(latlng[1])));
        }

        return calculateResult;
    }
}
